from pylab import *
import scipy.ndimage
from fast12 import detect
import sys

import simplejson

import numpy as np
import matplotlib.pyplot as plt






if __name__ == '__main__':
    if len(sys.argv) < 2:
        print sys.argv[0], '<job_file.json>'
        raise Exception('Insufficient number of parameters')

    finput = open(sys.argv[1])
    job_params = simplejson.load(finput)
    finput.close()

    fileroot = job_params['root_directory']

    ppL = []
    imgL = []

    for framenum in range(0, 4,2):
        filename = fileroot+'/frames/'+job_params['filename_format']%framenum
        ftfile = fileroot+'/fastcorners/'+job_params['filename_format']%framenum

        imgL.append(imread(filename))
        features = loadtxt(ftfile)

        ppL.append(array(features))


    fig = figure(1)
    ax = subplot(111)

    idx = 0
    pp = ppL[idx]

    #ax.imshow(.2+.8*imgL[0])
    line, = ax.plot(pp[:,0], pp[:,1], 'r+', mew=1, picker=5)
    axis('equal')
    ylim(750,0)
    xlim(0,1000)


    def onpick(event):

        if event.artist!=line: return True

        N = len(event.ind)
        if not N: return True

        print event.ind
        return True

    fig.canvas.mpl_connect('pick_event', onpick)

    plt.show()

